#pragma once

#include "Singleton.h"

#include <boost/asio.hpp>
#include <boost/beast.hpp>
#include <boost/beast/http.hpp>
#include <boost/filesystem.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <json/json.h>
#include <json/reader.h>
#include <json/value.h>
#include <hiredis/hiredis.h>
#include <unordered_map>
#include <map>
#include <queue>
#include <functional>
#include <memory>
#include <atomic>
#include <mutex>
#include <condition_variable>
#include <string>
#include <iostream>

enum ErrorCodes {
	Success = 0,
	Error_Json = 1001,		// Json解析错误
	RPCFailed = 1002,		// RPC请求错误
	VerifyExpired = 1003,	// 验证码过期
	VerifyCodeErr = 1004,	// 验证码错误
	UserExist = 1005,		// 用户已经存在
	PasswdErr = 1006,		// 密码错误
	EmailNotMatch = 1007,	// 邮箱不匹配
	PasswdUpFailed = 1008,  // 更新密码失败
	PasswdInvalid = 1009,   // 密码更新失败
	TokenInvalid = 1010,	// Token失效
	UidInvalid = 1011,		// uid无效
};

#define CODEPREFIX "code_"

// 在对象析构时执行对应分支的处理
class Defer
{
public:
	Defer(std::function<void()> func) : m_func(func) {

	}

	~Defer() {
		m_func();
	}

private:
	std::function<void()> m_func;
};

#define USERIPPREFIX  "uip_"
#define USERTOKENPREFIX  "utoken_"
#define IPCOUNTPREFIX  "ipcount_"
#define USER_BASE_INFO "ubaseinfo_"
#define LOGIN_COUNT  "logincount"


